package com.itany.corejava.day08;

import javax.swing.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Test6 {

    public static void main(String[] args) throws Exception {


        String targetTimeStr= JOptionPane.showInputDialog("请输入关机时间格式yyyy-MM-dd HH:mm:ss");


        while(!targetTimeStr.matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}")){
            System.out.println("时间格式不正确，请重新输入");
            targetTimeStr= JOptionPane.showInputDialog("请输入关机时间格式yyyy-MM-dd HH:mm:ss");
        }


        DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date targetTime=format.parse(targetTimeStr);


        while(true){

            Date now=new Date();

            System.out.println(format.format(now));

            if(targetTime.before(now)){
                break;
            }

            Thread.sleep(1000);


        }

//        Runtime.getRuntime().exec("shutdown -s -t 0");

        System.out.println("关机");
    }






}
